<?php

namespace App\Http\Requests\base;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait WarehouseRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'name' => 'required|max:255',
            'city' => 'required',
            'district' => 'required',
            'address' => 'required',
            'mobile' => 'required',
        ], [
            'name.required' => '请填写名称',
            'name.max' => '名称长度不能超过255个字符',
            'city.required' => '请选择城市',
            'district.required' => '请选择区县',
            'address.required' => '请填写详细地址',
            'mobile.required' => '请填写联系电话',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
